//ex10_10_5.cpp
//C:10.12:stacker.cpp -- testing the Stack class
#include <ctype.h>
#include <iostream>
#include <cctype> // or ctype.h
#include "Stack.h"

int main(void)
{
    using namespace std;
    customer cust;
    Stack st; // create an empty stack
    double sum = 0.0;
    char ch;
    unsigned long po;
    cout << "Please enter A to add a purchase order,\n"
         << "P to process a PO, or Q to quit.\n";
    while(cin >> ch && toupper(ch) != 'Q')    
    {
        while(cin.get() != '\n')
        {
            continue;
        }
        if(!isalpha(ch))
        {
            cout << '\a';
            continue;
        }
        switch (ch) 
        {
            case 'A':
            case 'a':
                cout << "Enter a customer's fullname to add: ";
                cin.getline(cust.fullname, 35);
                cout << "Enter a customer payment: ";
                cin >> cust.payment;
                if(st.isfull())
                {
                    cout << "stack already full\n";
                }
                else 
                {
                    st.push(cust);
                }
                break;
            case 'P':
            case 'p':
                if(st.isempty())
                {
                    cout << "stack already empty\n";
                }    
                else
                {
                    st.pop(cust);
                    sum += cust.payment;
                    // cout << "PO #" << po << " popped\n";
                    cout << cust.fullname << "is popped!\n";
                    cout << cust.payment << "is popped!\n";
                    cout << "sum payment = " << sum << '\n';
                }
                break;    
        }
        cout << "Please enter A to add a purchase order,\n"
             << "P to process a PO, or Q to quit.\n";
    }     
    cout << "Bye\n";
}